package com.baseDemo.ws.impl;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.activation.DataHandler;
import javax.jws.WebService;

import com.baseDemo.ws.IHelloService;
import com.baseDemo.ws.bean.BaseFileBean;

@WebService(endpointInterface = "com.baseDemo.ws.IHelloService", serviceName = "HelloService")
public class HelloService implements IHelloService {

	@Override
	public String say(String name) {
		return "hello:" + name;
	}

	@Override
	public Integer uploadBaseFileBean(BaseFileBean fileBean) throws IOException  {
		String name = fileBean.getName();
		DataHandler dh = fileBean.getDataHandler();
		System.out.println(name + "---------" + dh.getContentType());
		// 将上传的 文件写入到  本地磁盘  
		InputStream is = dh.getInputStream();
		FileOutputStream fos = new FileOutputStream("D:\\logo1.gif");
		byte[] bytes = new byte[2048];
		int len = 0;
		while ((len = is.read(bytes)) != -1) {
			fos.write(bytes, 0, len);
		}
		fos.flush();
		fos.close();
		is.close();

		return 1;
	}

}
